<template>
    <div>
        <table border="1">
            <tbody>
                <tr>
                    <th>id</th>
                    <th>
                        <input type="text" v-model="data.Id">
                    </th>
                </tr>
                <tr>
                    <th>姓名</th>
                    <th>
                        <input type="text" v-model="data.Name">
                    </th>
                </tr>
                <tr>
                    <th>性别</th>
                    <th>
                        <input type="radio" v-model="data.Sex" name="Sex" value="男">男
                        <input type="radio" v-model="data.Sex" name="Sex" value="女">女
                    </th>
                </tr>
                <tr>
                    <th>年龄</th>
                    <th>
                        <input type="text" v-model="data.Age">
                    </th>
                </tr>
                <tr>
                    <th>状态</th>
                    <th>
                        <input type="radio" v-model="data.State" name="State" value="false">禁用
                        <input type="radio" v-model="data.State" name="State" value="true">启用
                    </th>
                </tr>
                <tr>
                    <th>会员等级</th>
                    <th>
                        <input type="text" v-model="data.LevelId">
                    </th>
                </tr>
                <tr>
                    <th>图片</th>
                    <th>
                        <input type="file"  @change="Up">
                        <img :src="'https://localhost:7101/'+data.Img" style="width: 100px; height: 100px;">
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="修改" @click="Update">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import router from '@/router';
const data=ref({
    "Id": 0,
  "Name": "",
  "Sex": "",
  "Age": 0,
  "CreateTime": "2025-04-05T12:07:36.980Z",
  "State": true,
  "LevelId": 0,
  "Delete": true,
  "Img": "",
  "LevelName": ""
})

const levelmodel=ref([{
    "LevelId": 0,
    "LevelName": ""
}])

const model=ref({
    "LevelName": ""
})
onMounted(()=>{
    Upmemder()
})


const rputer=useRoute();

const Upmemder=()=>{
    var val=rputer.query.Id;
    axios.get("https://localhost:7101/api/Member/Detail",{params:{Id:val}}).then(res=>{
        data.value=res.data;
    })
}


const rou=useRouter();

const Update=()=>{
    if(confirm('确定修改吗')){
        axios.put("https://localhost:7101/api/Member/Update",data.value).then(res=>{
        if(res.data>0){
            alert('修改成功')
            rou.push({path:'/ShowView'})
        }
        else{
            alert('失败')
        }
    })
    }
    
}

const Up=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();

    fd.append("file",f);

    if(f.size>1024*1024*2){
        alert('图片不能超过2mb')
        return;
    }
    if(f.type!="image/jpeg" && f.type!="image/png"){
        alert('图片格式不正确')
        return;
    }

    axios.post("https://localhost:7101/api/UpLoad/Upload",fd).then(res=>{
        data.value.Img=res.data;
    })

}


</script>

